home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / ACG.h < prev    next >
C/C++ Source or Header  |  1989-10-19  |  2KB  |  72 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor
  10. accepts responsibility to anyone for the consequences of using it
  11. or for whether it serves any particular purpose or works at all,
  12. unless he says so in writing.  Refer to the GNU CC General Public
  13. License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute
  16. GNU CC, but only under the conditions described in the
  17. GNU CC General Public License.   A copy of this license is
  18. supposed to have been given to you along with GNU CC so you
  19. can know your rights and responsibilities.  It should be in a
  20. file named COPYING.  Among other things, the copyright notice
  21. and this notice must be preserved on all copies.  
  22. */
  23. #ifndef _ACG_h
  24. #define _ACG_h 1 
  25.  
  26. #include <RNG.h>
  27. #include <math.h>
  28. #pragma once
  29.  
  30. //
  31. //    Additive number generator. This method is presented in Volume II
  32. //    of The Art of Computer Programming by Knuth. I've coded the algorithm
  33. //    and have added the extensions by Andres Nowatzyk of CMU to randomize
  34. //    the result of algorithm M a bit    by using an LCG & a spatial
  35. //    permutation table.
  36. //
  37. //    The version presented uses the same constants for the LCG that Andres
  38. //    uses (chosen by trial & error). The spatial permutation table is
  39. //    the same size (it's based on word size). This is for 32-bit words.
  40. //
  41. //    The ``auxillary table'' used by the LCG table varies in size, and
  42. //    is chosen to be the the smallest power of two which is larger than
  43. //    twice the size of the state table.
  44. //
  45.  
  46. class ACG : public RNG {
  47.  
  48.     unsigned long initialSeed;    // used to reset generator
  49.     int initialTableEntry;
  50.  
  51.     unsigned long *state;
  52.     unsigned long *auxState;
  53.     short stateSize;
  54.     short auxSize;
  55.     unsigned long lcgRecurr;
  56.     short j;
  57.     short k;
  58.  
  59. protected:
  60.  
  61. public:
  62.     ACG(unsigned long seed = 0, int size = 55);
  63.     virtual ~ACG();
  64.     //
  65.     // Return a long-words word of random bits
  66.     //
  67.     virtual unsigned long asLong();
  68.     virtual void reset();
  69. };
  70.  
  71. #endif
  72.